"""
pip install alibabacloud-vod20170321==3.2.0
"""
from alibabacloud_vod20170321.client import Client as vod20170321Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_vod20170321 import models as vod_20170321_models
from alibabacloud_tea_util import models as util_models
from django.conf import settings


def get_play_auth(vid):
    try:
        config = open_api_models.Config(
            settings.ALI_VOD_ID,
            settings.ALI_VOD_SECRET
        )
        config.endpoint = settings.ALI_VOD_ENDPOINT

        client = vod20170321Client(config)
        get_video_play_auth_request = vod_20170321_models.GetVideoPlayAuthRequest(
            video_id=vid, auth_info_timeout=settings.ALI_AUTH_INFO_TIMEOUT
        )
        runtime = util_models.RuntimeOptions()
        res = client.get_video_play_auth_with_options(get_video_play_auth_request, runtime)
        play_auth = res.body.play_auth
        return play_auth
    except Exception as e:
        pass
